package com.yuzhenxin.coursesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yuzhenxin.coursesystem.entity.StudentDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Map;

@Mapper
public interface StudentMapper extends BaseMapper<StudentDO> {

    //根据token查询学生
    @Select("select * from student where token='${token}'")
    Map<String, Object> selectStudentByToken(@Param("token") String token);

    //根据学号更新学生token
    @Update("update student set token='${token}' where studentId='${studentId}'")
    void updateTokenByNo(@Param("token") String token, @Param("studentId") String studentId);

    //根据学号判断用户是否初次登录
    @Select("select token from student where studentId='${studentId}'")
    String tokenIsExist(@Param("studentId") String studentId);

    @Select("SELECT count(name) as total,SUM(CASE WHEN sex = '男' THEN 1 ELSE 0 END) AS boy,SUM(CASE WHEN sex = '女' THEN 1 ELSE 0 END) AS girl FROM student")
    Map<String, String> getStatistic();
}
